import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 自定义跳转
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('@/views/Home'),
      children: [
        {
          path: '/index',
          name: 'Index',
          component: () => import('@/views/Index')
        },
        {
          path: '/member/list',
          name: 'MemberList',
          component: () => import('@/views/member/MemberList')
        },
        {
          path: '/article/darftBox',
          name: 'ArticleDraftBox',
          component: () => import('@/views/article/ArticleDraftBox')
        },
        {
          path: '/article/list',
          name: 'ArticleList',
          component: () => import('@/views/article/ArticleList')
        },
        {
          path: '/article/publish',
          name: 'ArticlePublish',
          component: () => import('@/views/article/ArticlePublish')
        },
        {
          path: '/article/review',
          name: 'ArticleReview',
          component: () => import('@/views/article/ArticleReview')
        },
        {
          path: '/tag/list',
          name: 'TagList',
          component: () => import('@/views/tag/TagList')
        },
        // 车型库管理
        {
          path: '/carModel/brandlist',
          name: 'BrandList',
          component: () => import('@/views/carModel/BrandList')
        },
        {
          path: '/carModel/category',
          name: 'CarCategory',
          component: () => import('@/views/carModel/CarCategory')
        },
        {
          path: '/carModel/carlist',
          name: 'CarList',
          component: () => import('@/views/carModel/CarList')
        },
        {
          path: '/carModel/modellist',
          name: 'CarModelList',
          component: () => import('@/views/carModel/CarModelList')
        },
        {
          path: '/carModel/manufacturerlist',
          name: 'ManufacturerList',
          component: () => import('@/views/carModel/ManufacturerList')
        },
        {
          path: '/carModel/parameterlist',
          name: 'ParameterList',
          component: () => import('@/views/carModel/ParameterList')
        },
        // 自有商品管理
        {
          path: '/commodity/commoditylist',
          name: 'Commodity',
          component: () => import('@/views/commodity/Commodity')
        },
        // 活动管理
        {
          path: '/activity/activitylist',
          name: 'ActivityList',
          component: () => import('@/views/activity/ActivityList')
        },
        {
          path: '/activity/recommendactivity',
          name: 'RecommendActivity',
          component: () => import('@/views/activity/RecommendActivity')
        },
        {
          path: '/activity/typemanagement',
          name: 'TypeManagement',
          component: () => import('@/views/activity/TypeManagement')
        },
        {
          path: '/activity/channelmanagement',
          name: 'ChannelManagement',
          component: () => import('@/views/activity/ChannelManagement')
        },
        // 消息管理
        {
          path: '/message/messagelist',
          name: 'MessageList',
          component: () => import('@/views/message/MessageList')
        },
        // 角色管理
        {
          path: '/role/rolemanagement',
          name: 'RoleManagement',
          component: () => import('@/views/role/RoleManagement')
        },
        // 管理员列表
        {
          path: '/admin/AdminList',
          name: 'AdminList',
          component: () => import('@/views/admin/AdminList')
        },
        // 操作日志
        {
          path: '/log/operationlog',
          name: 'OperationLog',
          component: () => import('@/views/log/OperationLog')
        },
        // 个人中心
        {
          path: '/personal/personal',
          name: 'Personal',
          component: () => import('@/views/personal/Personal')
        } /*,
        {
          path: '/activity/list',
          name: 'ArticleDarfBox',
          component: () => import('@/views/article/ArticleDarftBox')
        },
        {
          path: '/activity/top',
          name: 'ArticleDarfBox',
          component: () => import('@/views/article/ArticleDarfBox')
        },
        {
          path: '/activity/categroy',
          name: 'ArticleDarfBox',
          component: () => import('@/views/article/ArticleDarfBox')
        },
        {
          path: '/activity/channel',
          name: 'ArticleDarfBox',
          component: () => import('@/views/article/ArticleDarfBox')
        } */
      ]
    }
  ]
})

/**
 * to   将访问路径
 * from 从哪个路径跳转
 * next 函数 放行 next() 放行 ；next(url) 强制跳转
 */
// router.beforeEach((to, from, next) => {
//  if (to.path === '/login') return next()
//  const token = window.sessionStorage.getItem('token')
//  if (!token) return next('/login')
//  next()
// })

export default router
